home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / mathpack / idamax.f < prev    next >
Text File  |  1989-08-17  |  3KB  |  78 lines

  1. c   imsl routine name   - vbla=idamax                                   vbib0010
  2. c
  3. c-----------------------------------------------------------------------
  4. c
  5. c   computer            - vax/double
  6. c
  7. c   latest revision     - january 1, 1978
  8. c
  9. c   purpose             - find the smallest index of the maximum
  10. c                           magnitude of a double precision vector
  11. c
  12. c   usage               - function idamax (n,dx,incx)
  13. c
  14. c   arguments    idamax - the smallest index i such that dabs(x(i))
  15. c                           is the maximum of dabs(x(j)) for j=1 to n.
  16. c                           (output)
  17. c                           x(i) refers to a specific element of dx.
  18. c                           see incx argument description.
  19. c                n      - length of vector x. (input)
  20. c                dx     - double precision vector of length n*incx.
  21. c                           (input)
  22. c                incx   - displacement between elements of dx. (input)
  23. c                           x(i) is defined to be dx(1+(i-1)*incx).
  24. c                           incx must be greater than zero.
  25. c
  26. c   precision/hardware  - double/all
  27. c
  28. c   reqd. imsl routines - none required
  29. c
  30. c   notation            - information on special notation and
  31. c                           conventions is available in the manual
  32. c                           introduction or through imsl routine uhelp
  33. c
  34. c   copyright           - 1978 by imsl, inc. all rights reserved.
  35. c
  36. c   warranty            - imsl warrants only that imsl testing has been
  37. c                           applied to this code. no other warranty,
  38. c                           expressed or implied, is applicable.
  39. c
  40. c-----------------------------------------------------------------------
  41. c
  42.       integer function idamax (n,dx,incx)
  43. c
  44. c                                  specifications for arguments
  45.       double precision   dx(1)
  46.       integer            n,incx
  47. c                                  specifications for local variables
  48.       double precision   dmax,xmag
  49.       integer            i,ii,ns
  50. c                                  first executable statement
  51.       idamax = 0
  52.       if (n.le.0) return
  53.       idamax = 1
  54.       if (n.le.1) return
  55.       if (incx.eq.1) go to 15
  56. c                                  code for increments not equal to 1.
  57.       dmax = dabs(dx(1))
  58.       ns = n*incx
  59.       ii = 1
  60.       do 10 i=1,ns,incx
  61.          xmag = dabs(dx(i))
  62.          if (xmag.le.dmax) go to 5
  63.          idamax = ii
  64.          dmax = xmag
  65.     5    ii = ii+1
  66.    10 continue
  67.       return
  68. c                                  code for increments equal to 1.
  69.    15 dmax = dabs(dx(1))
  70.       do 20 i=2,n
  71.          xmag = dabs(dx(i))
  72.          if (xmag.le.dmax) go to 20
  73.          idamax = i
  74.          dmax = xmag
  75.    20 continue
  76.       return
  77.       end
  78.